#include<iostream>
using namespace std;
//节点类
class Node
{
	public:
		int data;
		Node *next;
}
//单链表类
class LinkList{
	private:
		Node * head;
	public:
		LinkList(){
			head = new Node;
			head->data = 0;
			head->next = null;
		};
		~LinkList(){delete head;};
		void CreateLinkList(int n);
		int GetLength();
		void Insert(int x,int i);
		int Del(int i);
		void Print();
		void DelLinkList();
		
}
void LinkList::CreateLinkList(int n)
{
	if(n<=0)throw"长度错误";
	Node * s,*p;
	p = head;
	while(n-->=0)
	{
		s = new Node;
		cout<<"请输入数值"<<endl;
		cin>>s->data;
		s->next = null;
		p->next = s;
		p = s;
	}
	cout<<"单链表创建完成"<<endl;
}
int LinkList::GetLength()
{
	int count=0;
	Node * p;
	p =head;
	while(p->next!=null)
	{
		count++;
		P = P->next;
	}
	cout<<"一共有"<<count<<"个节点"<<endl;
	return count;
	
}
void LinkList::Insert(int x,int i)
{
	if(i<=0&&i>(GetLength()))throw"输入的节点位置错误";
	Node *s,*p;
	int count = 1;
	p = head->next;
	while(count<i-1)
	{
		p = p->next;
		count++;
	}
	s = new Node;
	s->data = x;
	s->next = p->next;
	p->next = s;
	
}
int LinkList::Del(int i)
{
	if(i<=0&&i>(GetLength()))throw"删除位置错误";
	Node *s,*p;
	int count=1;
	p = head;
	while(count<i)
	{
		p = p->next;
		count++;
	}
	s = p->next;
	p->next = s->next;
	cout<<"删除"<<s->data<<"成功";
	delete s;
	
	
}
void LinkList::Print()
{
	Node *p;
	int count =0;
	p = head;
	while(p->next!=null)
	{
		p = p->next;
		count++;
		cout<<p->data<<"---";
		
	}
	if(p->next==null)
	{cout<<p->data;}
cout<<"一共有"<<count<<"个节点"<<endl;
	
}
void LinkList::DelLinkList()
{
	Node *p,*s;
	s = head;
	while(s->next!=null)
	{
		p = s;
		s = s-next;
		delete p;
	}
}
void main()
{
	cout<<"hi"<<endl;
	system("pause");
}